package com.romotc.qqrobot.webqq.qqInterfaceLog;

import java.text.SimpleDateFormat;

import org.json.JSONObject;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.qqrobot.bean.QQUserFriend;
import com.romotc.qqrobot.bean.QQUserFriendService;
import com.romotc.qqrobot.config.bean.QQUrlWatcherConfig;
import com.romotc.qqrobot.webqq.bean.Poll2_ResponseBody;
import com.romotc.qqrobot.webqq.bean.Poll2_ResponseBody_Result;
import com.romotc.qqrobot.webqq.qqInterfaceCall.Get_msg_tip_InterCall;
import com.romotc.qqrobot.webqq.qqInterfaceCall.QQInterfaceCall;
import com.romotc.qqrobot.webqq.qqInterfaceCall.Send_buddy_msg2_InterCall;
import com.romotc.qqrobot.webqq.qqInterfaceCall.dataProcessor.EmptyProcessor;
import com.romotc.scache.RequestSpy;
/**
 * 接受到消息之后 转发给相应的客服QQ
 * @author Administrator
 *
 */
public class Poll2_Forward2CustService_Log extends Poll2_Processor_Log {
@Override
	public boolean checkSkipLog(RequestSpy rqSpy, QQUrlWatcherConfig config) {
		// TODO Auto-generated method stub
		return false;
	}
@Override
	String getPollType() {
		// TODO Auto-generated method stub
		return null;
	}
@Override
	void processPollEmpty(RequestSpy rqSpy, QQUrlWatcherConfig config,
			Poll2_ResponseBody response) {
		// TODO Auto-generated method stub
		
	}
	@Override
	void processPollResult(RequestSpy rqSpy, QQUrlWatcherConfig config,
			Poll2_ResponseBody_Result result, Poll2_ResponseBody response,
			int resultIdx) {
		// TODO Auto-generated method stub
		
	}
	
	
@Override
	void processPollMsg(RequestSpy rqSpy, QQUrlWatcherConfig config,
			Poll2_ResponseBody response) {
	QQInterfaceCall sendMsgCall = new Send_buddy_msg2_InterCall();
	
	JSONObject reqDataObj = new JSONObject();
	//查找发送消息的客户对应的客服人员QQ的Uin
	QQUserFriend qservice = QQUserFriendService.qryQFriendByMarkName("d00098");
	
	if(response.getResult() != null && response.getResult().size() > 0)
		for(Poll2_ResponseBody_Result result : response.getResult()) {
			

			if(result.getValue().getContentMsg() != null) {
				try {
					
					Get_msg_tip_InterCall tipcall = Get_msg_tip_InterCall.getInstance();
					tipcall.call(QQLogedin.getCurQqLogedIn(rqSpy), reqDataObj, EmptyProcessor.getInstance());
					
					reqDataObj.put(Send_buddy_msg2_InterCall.Key_MsgStr, ++i + " " + result.getValue().getContentMsg());
					reqDataObj.put(Send_buddy_msg2_InterCall.Key_Send2Uin, qservice.getUin());
					
					sendMsgCall.call(QQLogedin.getCurQqLogedIn(rqSpy), reqDataObj, EmptyProcessor.getInstance());
					Thread.sleep(1000* 5);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}	
	}
private  static int i = 0;
private static SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
